<template>
	<view class="search-box s-flex-r-s-c">
		<view class="wrap s-flex-r-s-c flex1">
			<input class="inp flex1" type="text" placeholder-class="pc" v-model="val" @input="input" @confirm="confirm" :placeholder="placeholder" />
			<u-icon v-if="val" size="30rpx" class="mr10" color="#BBBBBB" @click="clear" name="close-circle"></u-icon>
			<u-icon v-else size="30rpx" class="mr10" color="#BBBBBB" name="search"></u-icon>
		</view>
		<slot></slot>
	</view>
</template>

<script>
	export default {
		name: "my-search",
		props: {
			placeholder: {
				type: String,
				default: '请输入'
			},
			value: { //(使用v-model语法糖: 1.props需为value; 2.需回调input事件)
				type: String,
				default: ''
			},
		},
		data() {
			return {
				val:""
			}
		},
		methods: {
			input(e) {
				this.$emit("input", e.detail.value);
			},
			confirm() {
				this.$emit("confirm");
			},
			clear() {
				this.val= '';
				this.$emit("input", '');
				this.$emit("confirm");
			},
		}
	}
</script>

<style lang="scss" scoped>
	.search-box{
		background-color: #ffffff;
		padding:22rpx 20rpx;
		.wrap {
			border: 2rpx solid #BBBBBB;
			background-color: #ffffff;
			padding: 6rpx 14rpx;
			box-sizing: border-box;
			border-radius: 16rpx;
			font-size: 28rpx;
			.inp{
				height: 50rpx;
			}
			.pc{
				color:#888888;
				font-size: 28rpx;
			}
		}
		
	}
</style>